<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit" :showHistoryBtn="true">
		<om-autoform ref="autoform" :checkedit="checkedit" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
		<om-white-space bgColor="#eee"></om-white-space>
	</om-addpage>
</template>

<script>
import { getUrl,confirmModal,errorModal } from '@/static/js/common.js';
import { formValidation,getWorkCacheKey,hasEditor,getEditorTitle, buildFormData, formModelLoad,tranferToEditors, changeEditor, configSelectData, hasValue,formShowLoading ,getFormFields, getEditor} from '@/static/js/formUtil.js';
import { mapState } from 'pinia';
import {useLoginUserStore} from '@/stores/login-user.js';
import urlUtil from '@/static/js/urlUtil.js'
export default {
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return buildFormData({
			checkedit:false,
			edit:false,
			menuName: '',
			promotionDate:"",
			id: '',
			busCode: '',
			formdata: {
				loanMoney:""
			},
			initValue: {
				zuserId:"",
				zuserName:"",
				loanMoney:"",
				busCode: ''
			},
			salary1:0,
			salary2:0,
			salary3:0,
			salaryPosId:"",
			edited:false,
			score1:0,
			score2:0,
			resultList:[],
			salaryList:[],
			dvid: null
		});
	},
	computed: {
		...mapState(useLoginUserStore, ['userName', 'userId'])
	},
	methods: {
		verifyCanEditEvaluateWay: function() {
			let _that = this;
			let postInitEvaluateWayFlag = _that.$refs.autoform.formdata.postInitEvaluateWayFlag
			if (postInitEvaluateWayFlag == true || postInitEvaluateWayFlag == "true") {
				if(_that.subEditorObj["workInfo"]){
					let posName = "";
					let rows = _that.subEditorObj["workInfo"].workList;
					for(let i = 0; i < rows.length; i++){
					    let row = rows[i];
					    if(row.salaryPosFlagStr){
					        posName = rows[i].posName;
					    }
					}
				}
				_that.om.toast(posName + '在《岗位信息档案》配置了转正评价方式，禁止编辑。');
				return false;
			}
			return true;
		},
		getWorkParamSalary(){
			let _that = this
			return {
				userId:_that.$refs.autoform.formdata.userId?_that.$refs.autoform.formdata.userId:''
			}
		},
		getScore(score1,score2,socre3,socre4){
			let _that  = this
			return _that.om.request(
				"tpromoteEvaluate/calComprehensiveScore",
				{
					selfScore: score1,
					parentScore:score2,
					trainingEvaluationScore: socre3,
					re_score: socre4
				}
			)
		},
		async calComprehensiveScore(score1,score2,socre3,socre4){
			let _that = this
			return await _that.getScore(score1,score2,socre3,socre4)
		},
		getWorkParam(){
			let _that = this
			return {
				parentId:_that.subEditorObj['workInfo'].workList[0].parentUserId,
				otherId:_that.$refs.autoform.formdata.userId
			}
		},
		formSubmit() {
			let _that = this;
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				if(this.checkedit){
					_that.om.formSave('commonForm/doCheckOrApproveUpdate', this.formdata, _that)
				}else{
					_that.om.formSave('tpromoteEvaluate/addTpromoteEvaluate', this.formdata, _that)
				}
			}
		},
		onSelectZpos(item){
			let _that = this;
			// this.om.request('tpromoteEvaluate/getUserList', { zposId: item.id }).then(res=>{
			// 	//if(res instanceof Array){
			// 	if(Object.prototype.toString.call(res)==='[object Array]'){
			// 		_that.$refs.autoform.changeEditor("userInfo","userId", "data", configSelectData(res, "id", "username"))
			// 	} else {
			// 		_that.om.toast(res.msg)
			// 	}
			// 	_that.$refs.autoform.initSelectIndex('userInfo','userId')
			// });
		},
		clearZpos(){
			let _that = this;
			_that.$refs.autoform.clear("topinfo","zposId")
			// _that.clearUser()
			// _that.$refs.autoform.changeEditor("userInfo","userId", "data",[])
		},
		onSelectUser(item){
			let _that = this;
			this.om.request('tpromoteEvaluate/verifyUser', { 
				userId: item.id,
				peId: _that.dvid
			}).then(res=>{
				if(res.succeed){
					if(res.value){
						errorModal(_that, "提示信息", res.value, function(){
							 _that.clearUser()
						})
					}else{
						_that.loadInfo(item.id)
					}
				}
			})
		},
		onSelectSalaryPos(item){
			let _that = this
			if(item.id != _that.salaryPosId){
				_that.$refs.autoform.changeEditor("title10","salaryPosId",{
					type:"datebox",
					prompt:"请选择"
				})
			}
		},
		loadInfo(userId){
			let _that = this;
			//加载信息
			var pro1 = this.om.request('tpromoteEvaluate/getNewDataInfo', { userId: userId });
			//加载薪资信息
			var pro2 = this.om.request('temployee/getSalaryInfo', { userId: userId});
			Promise.all([pro1,pro2]).then(res => {
				if (res[0].succeed) {
				     let data = res[0].value;
					 for(var i in data.userResponse) {
						 if(_that.$refs.autoform.formdata.hasOwnProperty(i)){
							 _that.$refs.autoform.formdata[i] = data.userResponse[i]
						 }
					 }
					 if(data.tpromoteEvaluate){
						 for(var i in data.tpromoteEvaluate){
							 if(_that.$refs.autoform.formdata.hasOwnProperty(i)){
								 if(!_that.$refs.autoform.formdata[i]){
									 _that.$refs.autoform.formdata[i] = data.tpromoteEvaluate[i]
								 }
							 }
						 }
						 let evaluateWayId = data.tpromoteEvaluate.evaluateWayId;
						 let postInitEvaluateWayFlag = evaluateWayId ? true : false;
						 _that.$refs.autoform.formdata.postInitEvaluateWayFlag = postInitEvaluateWayFlag;
						 _that.$refs.autoform.formdata.evaluateWayId = evaluateWayId
						 _that.$refs.autoform.formdata.evaluateWay =  data.tpromoteEvaluate.evaluateWay
					 }else{
						_that.$refs.autoform.formdata.postInitEvaluateWayFlag = ""
					 }
					 
					 for(var i in data.posResponse){
						 if(_that.$refs.autoform.formdata.hasOwnProperty(i)){
							 _that.$refs.autoform.formdata[i] = data.posResponse[i]
						 }
					 }
					 for(var i in data.scoreResponse){
						 if(_that.$refs.autoform.formdata.hasOwnProperty(i)){
							 _that.$refs.autoform.formdata[i] = data.scoreResponse[i]
						 }
					 }
					 if(_that.subEditorObj["workInfo"]){
						 _that.subEditorObj["workInfo"].workList = res[0].value.tworkInfos
					 }
					 if(_that.subEditorObj["title_evaluate"]){
						 	if(_that.subEditorObj["title_evaluate"]){
						 		let att = {
						 			showAdd:false,
						 			showDel:false,
						 			getWorkParam:'getWorkParam'
						 		}
						 		let configData = _that.subConfigData["title_evaluate"]
						 		if(hasEditor("title_evaluate","itemName",configData)){
						 			let title = getEditorTitle("title_evaluate","itemName",configData)
						 			att.titleTemplate = "<%= itemName %>"
						 		}
								if(_that.$refs.autoform.formdata.userId == _that.userId){
									if(hasEditor("title_evaluate","selfEvaluateScore",configData)){
										let title = getEditorTitle("title_evaluate","selfEvaluateScore",configData)
										att.subtitle1Template = title+":<%= selfEvaluateScore || '点击进行评价'%>"
									}
						 		_that.$refs.autoform.changeEditor("title_evaluate","evaluateStr",att)
						 	}else if(_that.subEditorObj['workInfo'].workList[0].parentUserId == _that.userId){
								if(hasEditor("title_evaluate","parentEvaluateScore",configData)){
										let title = getEditorTitle("title_evaluate","parentEvaluateScore",configData)
										att.subtitle1Template = title+":<%= parentEvaluateScore || '点击进行评价'%>"
									}
								_that.$refs.autoform.changeEditor("title_evaluate","evaluateStr",att)
							}
						}
						if(res[0].value.evaluateList){
							if(_that.userId == _that.subEditorObj['workInfo'].workList[0].parentUserId){
								if(_that.checkedit){
									_that.subEditorObj["title_evaluate"].workList = res[0].value.evaluateList
								}
							}
							if(_that.userId == _that.$refs.autoform.formdata.userId){
								if(res[0].value.tpromoteEvaluate.evaluateWay){
									_that.subEditorObj["title_evaluate"].workList = res[0].value.evaluateList
								}
							}
						}
					 }
				}
				if(res[1].succeed){
					let d = res[0].value.temployeeResponse;
					let formdata = _that.$refs.autoform.formdata
					formdata.sexName = d.sexName
					formdata.birthdate = d.birthdate
					formdata.birthPlace = d.birthPlace
					formdata.entrydate = d.entrydate
					formdata.areaName = d.areaName
					formdata.idTypeName = d.idTypeName
					formdata.idcard = d.idcard
					formdata.mobile = d.mobile
					formdata.highestEduName = d.highestEduName
					formdata.certificateValidDate = d.certificateValidDate
					formdata.nationName = d.nationName
					formdata.marriageName = d.marriageName
					formdata.politicalName = d.politicalName
					formdata.bloodTypeName = d.bloodTypeName
					formdata.userno = d.userno
					formdata.registerCategoryName = d.registerCategoryName
					formdata.birthaddress = d.birthaddress
					formdata.currentaddress = d.currentaddress
					formdata.salarycatName = d.salarycatName
					formdata.attributeName = d.attributeName
					formdata.customCateAName = d.customCateAName
					formdata.roleName = d.roleName
					formdata.salaryPosName = d.salaryPosName
					formdata.salaryPosInstName = d.salaryPosInstName
					for (var i = 1; i <= 19; i++) {
						_that.$refs.autoform.formdata['salary'+i + '_'] = d['salary' + i]
					}
					
					_that.om.request(
						"tinstitution/getInstInfo",
						{
							instId:d.salaryPosInstId
						}
					).then(res=>{
						_that.$refs.autoform.formdata.instLevelId =  res.value.instcatId
						_that.$refs.autoform.formdata.instLevelName =  res.value.instcatName
					})
				}
			})
		},
		clearUser(){
			let _that = this;
			_that.$refs.autoform.clear("userInfo", "userId")
			for(var e in _that.$refs.autoform.formdata){
				if(!["zposId", "zposName","zinstId","zinstName","zuserId","zuserName"].includes(e)){
					_that.$refs.autoform.formdata[e] = ""
				}
			}
		},
		onSelectTime(){
			let _that = this
			if(Number(_that.formdata.salary1) === _that.salary1 && Number(_that.formdata.salary2) === _that.salary2 && Number(_that.formdata.salary3) === _that.salary3){
				errorModal(_that,"提示信息",'薪资项目未做调整，不能选择“调薪生效日期”！',function(){
					_that.$refs.autoform.clear("title10","salaryEffectDate")
				})
			}
		},
		onSelectResult(item){
			let _that = this;
			let title = '上级评价得分低于'
			if(_that.$refs.autoform.hasEditor("resultInfo","parentScore")){
				if(!_that.$refs.autoform.formdata.parentScore){
					_that.om.toast("请先进行上级评价")
					_that.$refs.autoform.clear('resultInfo','resultCode')
					return
				}
				if(item.code == "37933"){
					if(Number(_that.$refs.autoform.formdata.parentScore)<_that.score2){
						errorModal(_that,'提示信息',title+_that.score2+'只能选择'+_that.resultList[2].dicname,()=>{
							_that.$refs.autoform.clear('resultInfo','resultCode')
						})
						return
					}
				}
				if(item.code == "37932"){
					if(Number(_that.$refs.autoform.formdata.parentScore)<_that.score1){
						errorModal(_that,'提示信息',title+_that.score1+'分不能转正',()=>{
							_that.$refs.autoform.clear('resultInfo','resultCode')
						})
						return
					}
				}
			}else{
				let title1 = _that.$refs.autoform.getEditorTitle("resultInfo","comprehensiveScore")
				if(_that.$refs.autoform.hasEditor("resultInfo","comprehensiveScore") && !_that.$refs.autoform.formdata.comprehensiveScore){
					if(_that.$refs.autoform.formdata.evaluateWayId){
						_that.om.toast("请先进行上级评价")
						_that.$refs.autoform.clear('resultInfo','resultCode')
						return
					}
				}
				if(item.code == "37932" && _that.$refs.autoform.hasEditor("resultInfo","comprehensiveScore")){
					if(Number(_that.$refs.autoform.formdata.comprehensiveScore)<_that.score1){
						errorModal(_that,'提示信息',title1+'低于'+_that.score1+'分不能转正',()=>{
							_that.$refs.autoform.clear('resultInfo','resultCode')
						})
						return
					}
				}
				if(item.code == "37933" && _that.$refs.autoform.hasEditor("resultInfo","comprehensiveScore")){
					if(Number(_that.$refs.autoform.formdata.comprehensiveScore)<_that.score2){
						errorModal(_that,'提示信息',title1+'低于'+_that.score2+'只能选择'+_that.resultList[2].dicname,()=>{
							_that.$refs.autoform.clear('resultInfo','resultCode')
						})
						return
					}
				}
			}
			if(item.code == "37933"){//延长试用期
				_that.$refs.autoform.changeEditor("resultInfo", "adjustDate", {
					type:"datebox",
					prompt:"请选择",
					required:true
				})
				_that.$refs.autoform.clear("resultInfo","promotionDate")
				_that.$refs.autoform.changeEditor("resultInfo", "promotionDate", {
					type: "labelbox",
					required:false
				})
			} else if(item.code == "37932") {//同意转正
				_that.$refs.autoform.changeEditor("resultInfo", "promotionDate", {
					type:"datebox",
					prompt:"请选择",
					required:true
				})
				_that.$refs.autoform.clear("resultInfo","adjustDate")
				_that.$refs.autoform.changeEditor("resultInfo", "adjustDate", {
					type: "labelbox",
					required: false
				})
				if(_that.promotionDate){
					_that.$refs.autoform.formdata.promotionDate = _that.promotionDate
				}
			} else {
				_that.$refs.autoform.clear("resultInfo","promotionDate")
				_that.$refs.autoform.changeEditor("resultInfo", "promotionDate", "type", "labelbox")
				_that.$refs.autoform.clear("resultInfo","adjustDate")
				_that.$refs.autoform.changeEditor("resultInfo", "adjustDate", "type", "labelbox")
			}
		},
		clearResult(){
			let _that = this;
			_that.$refs.autoform.clear("resultInfo", "resultCode")
			_that.$refs.autoform.clear("resultInfo","promotionDate")
			_that.$refs.autoform.changeEditor("resultInfo", "promotionDate", "type", "labelbox")
			_that.$refs.autoform.clear("resultInfo","adjustDate")
			_that.$refs.autoform.changeEditor("resultInfo", "adjustDate", "type", "labelbox")
		},
		loadSalaryPos(){
			let _that = this;
			var pro1 = this.om.request('orgInstPosUserOfficial/getPosList', { 'user.id': _that.$refs.autoform.formdata.userId })
			var pro2 = this.om.request('tsysdict/getListByCode', { code: "23645"})
			Promise.all([pro1, pro2]).then(res => {
				_that.$refs.autoform.changeEditor("title10", "salaryPosId", "data", configSelectData(res[0],"id","posName"))
				if(!_that.$refs.autoform.formdata.resultCode){
					_that.$refs.autoform.formdata.salaryPosId = _that.$refs.autoform.formdata.posId
					_that.$refs.autoform.formdata.salaryPosName = _that.$refs.autoform.formdata.posName
					_that.$refs.autoform.formdata.salaryWay1 = _that.$refs.autoform.formdata.salaryWay
					_that.$refs.autoform.formdata.posGrade1 = _that.$refs.autoform.formdata.posGrade
					_that.$refs.autoform.formdata.levelSalaryRange = _that.$refs.autoform.formdata.gradeSalaryRange
					_that.$refs.autoform.formdata.monthSalary = _that.$refs.autoform.formdata.monthSalary_
					_that.$refs.autoform.formdata.yearSalary = _that.$refs.autoform.formdata.yearSalary_
					_that.$refs.autoform.formdata.effectDate = _that.$refs.autoform.formdata.effectDate_
					for(var e in _that.$refs.autoform.formdata){
						if(_that._.startsWith(e, "salary") && _that._.endsWith(e, "_")){
							_that.$refs.autoform.formdata[e.substr(0, e.length-1)] = _that.$refs.autoform.formdata[e]
						}
					}
				}
				_that.$refs.autoform.initSelectIndex("title10", "salaryPosId")
				_that.$refs.autoform.changeEditor("title10", "salaryLevelId", "data", configSelectData(res[1],"id","dicname"))
				_that.$refs.autoform.initSelectIndex("title10", "salaryLevelId")
				
			})
		},
		async getSalaryList(id,posId){
			let _that = this
			let res = await  _that.om.request(
				"tempInstAdjust/getSalaryList1",
				{
					userId: id,
					posId:posId,
					busCode: _that.busCode
				}
			)
				for(let item of res.value){
					if(item.salaryName != 'salary1' && item.salaryName != 'salary2' && item.salaryName != 'salary3' && item.salaryName !=  'salary4'){
						item.showSubTitle2 = false
					}
				}
				_that.subEditorObj["title_salary"].workList = res.value
		},
		 initLoad(options) {
			let _that = this;
			let fileId = options.fileId
			if (!this.busCode) {
				return;
			}
			//制表岗位
			var ajaxArr = [
				{
					url:'wxPosBusiAuth/isnewList',
					param:{ 
						code: _that.busCode ,
					}, 
					method:'post',
				},
				urlUtil.dataDictInitValueUrl('DD014010002'),
				urlUtil.dataDictInitValueUrl('DD014010003'),
				{
					url:'tsysdict/getCombobox',
					param:{ 
						code:'39782' ,
					}
				},
				{
					url:'tpromoteEvaluate/getUserList',
					param:{ 
						
					},
					method:'post',
				},
				{
					url:"wxPosBusiAuth/defaultTableMaker",
					param: {
						code: _that.busCode
					},
					method: "post"
				},
				urlUtil.dictZeroComboboxUrl('36796'),
			]
			if(fileId) {
				//加载数据
				ajaxArr.push({
					url:'tpromoteEvaluate/getInfo',
					param:{id:fileId}, 
					method:'post'});
				if(_that.checkedit){
					ajaxArr.push({
						url:'tpromoteEvaluate/canEditData',
						param:{id:fileId}, 
						method:'post'});
				}	
				
				_that.dvid = fileId;
			}
			//多个AJAX全部完成时开始执行
				formModelLoad(ajaxArr, function(res, mainData) {
						var defaultPosId = res[5].value.id || '';
						var defaultPosName = res[5].value.posName || '';
						var defaultInstId = res[5].value.instId || '';
						var defaultInstName = res[5].value.instName || '';
						_that.score1 = res[1].value
						_that.score2 = res[2].value
						if(!_that.checkedit){
							changeEditor('topinfo','zposId', 'data', configSelectData(res[0], 'id', 'posname'),mainData);
						}
						changeEditor('resultInfo','re_resultCode', 'data', configSelectData(res[3], 'code', 'dicname'),mainData);
						changeEditor('userInfo','userId', 'data', configSelectData(res[4], 'id', 'username'),mainData);
						if(res[4].length == 0){
							errorModal(_that, "提示信息", "没有可选择的转正人员", function(){
								
							})
						}
						changeEditor('title_probationInfo','evaluateWayId', 'data', configSelectData(res[6], 'id', 'dicname'),mainData);
						if(_that.subEditorObj["title_salary"]){
							let att = {
								showAdd:false,
								showDel:false,
								getWorkParam:'getWorkParamSalary'
							}
							let configData = _that.subConfigData["title_salary"]
							if(hasEditor("title_salary","itemName",configData)){
								att.titleTemplate = "<%= itemName || '未填写'%>"
							}
							if(hasEditor("title_salary","beforeAdjustId",configData)){
								let title = getEditorTitle("title_salary","beforeAdjustId",configData)
								att.subtitle1Template = title + ":<%= beforeAdjust || '无'%>"
							}
							if(hasEditor("title_salary", "afterAdjustId",configData)){
								let title = getEditorTitle("title_salary","afterAdjustId",configData)
								if(att.subtitle1Template){
									att.subtitle1Template = att.subtitle1Template +' | '+title + ":<%= afterAdjust || '未填写'%>"
								}else{
									att.subtitle1Template =title + ":<%= afterAdjust || '未填写'%>"
								}
							}
							if(hasEditor("title_salary","salary",configData)){
								let title = getEditorTitle("title_salary","salary",configData)
								att.subtitle2Template = title + ":<%= salary || ''%>"
							}
							if(hasEditor("title_salary","remark",configData)){
								let title = getEditorTitle("title_salary","remark",configData)
								att.subtitle3Template = title + ":<%= remark || '未填写'%>"
							}
							changeEditor("title_salary","salaryStr",att,mainData)
						}
						if(_that.subEditorObj["workInfo"]){
							let att = {
								showAdd:false,
								showDel:false
							}
							let configData = _that.subConfigData["workInfo"]
							if(hasEditor("workInfo","posName",configData)){
								let title = getEditorTitle("workInfo","posName",configData)
								att.titleTemplate = "<%= posName %>"
							}
							changeEditor("workInfo","workStr",att,mainData)
						}
						if(_that.subEditorObj["title_evaluate"]){
							let att = {
								showAdd:false,
								showDel:false,
								getWorkParam:'getWorkParam'
							}
							let configData = _that.subConfigData["title_evaluate"]
							if(hasEditor("title_evaluate","itemName",configData)){
								let title = getEditorTitle("title_evaluate","itemName",configData)
								att.titleTemplate = "<%= itemName %>"
							}
							changeEditor("title_evaluate","evaluateStr",att,mainData)
						}
						if(fileId){
							var fieldArr = getFormFields(mainData)
							fieldArr.push("id")
							for(var i in res[7].value){
								if(res[7].value[i]){
									//if(res[2].value[i] instanceof Object){
									if(Object.prototype.toString.call(res[7].value[i])==='[object Object]'){
										for(var j in res[7].value[i]){
											if(fieldArr.includes(j)){
												if(!_that.$refs.autoform.formdata[j]){
													if(j == "promotionDate"){
														if(res[7].value[i]['promotionDate']){
															_that.promotionDate = res[7].value[i]['promotionDate']
														}else{
															_that.promotionDate =  res[7].value[i]['probationEndDate']
														}
													}else{
														_that.$refs.autoform.$set(_that.$refs.autoform.formdata, j, res[7].value[i][j])
														_that.$set(_that.formdata, j, res[7].value[j])
													}
												}
											}
										}
									}else if(fieldArr.includes(i)){
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata, i, res[7].value[i])
										_that.$set(_that.formdata, i, res[7].value[i])
									}
								}
							}
							if(_that.subEditorObj["workInfo"]){
								let workList = _that._.cloneDeep(res[7].value.tworkInfos)
								 _that.subEditorObj["workInfo"].workList = workList
								 _that.$refs.autoform.$set(_that.$refs.autoform.formdata,"workStr",JSON.stringify(workList))
								 _that.$set(_that.formdata,"workStr",JSON.stringify(workList))
							}
							if(_that.subEditorObj["title_evaluate"]){
								let evaluateList = _that._.cloneDeep(res[7].value.evaluateList)
								 _that.subEditorObj["title_evaluate"].workList = evaluateList
								 _that.$refs.autoform.$set(_that.$refs.autoform.formdata,"evaluateStr",JSON.stringify(evaluateList))
								 _that.$set(_that.formdata,"evaluateStr",JSON.stringify(evaluateList))
								let score1 = 0 
								let score2 = 0
								let score3 = 0
								for(let d of evaluateList){
									score1 += Number(d.standardScore)
									score2 += Number(d.parentEvaluateScore)
									score3 += Number(d.selfEvaluateScore)
								}
								let title1 = getEditorTitle("title_evaluate","standardScore",_that.subConfigData["title_evaluate"])
								let title2 = getEditorTitle("title_evaluate","parentEvaluateScore",_that.subConfigData["title_evaluate"])
								let title3 = getEditorTitle("title_evaluate","selfEvaluateScore",_that.subConfigData["title_evaluate"])
								changeEditor("title_evaluate","evaluateStr",{
									subBottomTitle:'合计:'+title1+'('+score1+')'+(title2?','+title2+'('+score2+')' :'')+(title3?','+title3+'('+score3+')' :'')
								},mainData)
							}
							if(_that.checkedit &&_that.subEditorObj['workInfo'].workList && _that.subEditorObj['workInfo'].workList[0].parentUserId == _that.userId){
								if(_that.subEditorObj["title_evaluate"]){
									let att = {
										showAdd:false,
										showDel:false,
										getWorkParam:'getWorkParam'
									}
									let configData = _that.subConfigData["title_evaluate"]
									if(hasEditor("title_evaluate","itemName",configData)){
										let title = getEditorTitle("title_evaluate","itemName",configData)
										att.titleTemplate = "<%= itemName %>"
									}
									if(hasEditor("title_evaluate","parentEvaluateScore",configData)){
										let title = getEditorTitle("title_evaluate","parentEvaluateScore",configData)
										att.subtitle1Template = title+":<%= parentEvaluateScore || '点击进行评价'%>"
									}
									changeEditor("title_evaluate","evaluateStr",att,mainData)
								}
							}else if(_that.$refs.autoform.formdata.userId == _that.userId){
								if(_that.subEditorObj["title_evaluate"]){
									let att = {
										showAdd:false,
										showDel:false,
										getWorkParam:'getWorkParam'
									}
									let configData = _that.subConfigData["title_evaluate"]
									if(hasEditor("title_evaluate","itemName",configData)){
										let title = getEditorTitle("title_evaluate","itemName",configData)
										att.titleTemplate = "<%= itemName %>"
									}
									if(hasEditor("title_evaluate","selfEvaluateScore",configData)){
										let title = getEditorTitle("title_evaluate","selfEvaluateScore",configData)
										att.subtitle1Template = title+":<%= selfEvaluateScore || '点击进行评价'%>"
									}
									changeEditor("title_evaluate","evaluateStr",att,mainData)
								}
							}
							if(_that.subEditorObj["title_salary"]  && _that.checkedit && res[7].value){
								if(res[7].value.salaryList){
									_that.subEditorObj["title_salary"].workList = res[7].value.salaryList
									let dataList = _that._.cloneDeep(res[7].value.salaryList)
									for(let item of dataList){
										if(item.salaryName != 'salary1' && item.salaryName != 'salary2' && item.salaryName != 'salary3' && item.salaryName != 'salary4'){
											item.showSubTitle2 = false
										}
									}
									_that.subEditorObj["title_salary"].workList = dataList
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"salaryStr",JSON.stringify(dataList))
									_that.$set(_that.formdata,"salaryStr",JSON.stringify(dataList))
								}else{
									_that.subEditorObj["title_salary"].workList =  []
								}
							}
							if(_that.$refs.autoform.formdata.resultCode){//评价结论有值时
								let code = _that.$refs.autoform.formdata.resultCode
								if(code == "37933"){//延长试用期
									changeEditor("resultInfo", "adjustDate", {
										type:"datebox",
										prompt:"请选择",
										required:true
									},null,mainData)
									changeEditor("resultInfo", "promotionDate", {
										type: "labelbox",
										required:false
									},null,mainData)
								} else if(code == "37932") {//同意转正
									_that.$refs.autoform.formdata.promotionDate = _that.promotionDate
									changeEditor("resultInfo", "promotionDate", {
										type:"datebox",
										prompt:"请选择",
										required:true
									},null,mainData)
									changeEditor("resultInfo", "adjustDate", {
										type: "labelbox",
										required: false
									},null,mainData)
								} else {
									changeEditor("resultInfo", "promotionDate", "type", "labelbox",mainData)
									changeEditor("resultInfo", "adjustDate", "type", "labelbox",mainData)
								}
							}
							 if(_that.$refs.autoform.formdata.userId && (_that.userId !== _that.$refs.autoform.formdata.userId)){
								 _that.loadOthers();
							 }else{
								 changeEditor("resultInfo","resultCode","type","labelbox",mainData)
								 changeEditor("resultInfo","resultCode","required",false,mainData)
								 changeEditor("resultInfo","promotionDate","type","labelbox",mainData)
								 changeEditor("resultInfo","remark2","type","labelbox",mainData)
							 }
							_that.$nextTick( async function(){
								_that.$refs.autoform.initSelectIndex("topinfo","zposId")
								_that.$refs.autoform.initSelectIndex('resultInfo','re_resultCode')
								_that.$refs.autoform.initSelectIndex('userInfo','userId')
								if(_that.$refs.autoform.formdata.zposId){
									_that.onSelectZpos({id:_that.$refs.autoform.formdata.zposId})
								}
								if(_that.checkedit &&  res[7].value && _that.subEditorObj["title_salary"]){
									for(let item of _that.subEditorObj["workInfo"].workList){
										if(item.salaryPosFlag || item.probationPosFlag){
											let configData = _that.subConfigData["title_salary"]
											let editor = getEditor("title_salary","afterAdjustId",configData)
											for(let salaryItem of _that.subEditorObj["title_salary"].workList){
												if(salaryItem.afterAdjustId){
													return
												}
											}
											if(editor.checkedit){
												await _that.getSalaryList(_that.$refs.autoform.formdata.userId,item.posId)
											}
										}
									}
								}
							})
						}
						_that.$nextTick(function(){
							// if(!_that.$refs.autoform.formdata.zposId){
							// 	_that.$refs.autoform.initSelectVal("topinfo","zposId")
							// 	if(_that.$refs.autoform.formdata.zposId){
							// 		_that.onSelectZpos({id:_that.$refs.autoform.formdata.zposId})
							// 	}
							// }
							
							if(!_that.$refs.autoform.formdata.zposId){
								_that.$refs.autoform.formdata.zposId = defaultPosId
								_that.$refs.autoform.formdata.zposName = defaultPosName
								_that.$refs.autoform.formdata.zinstId = defaultInstId
								_that.$refs.autoform.formdata.zinstName = defaultInstName
								_that.$nextTick(function() {
									_that.$refs.autoform.initSelectIndex('topinfo',"zposId")
								})
							}else{
								_that.$refs.autoform.initSelectIndex('topinfo',"zposId")
							}
						})
			},options)
		},
		loadOthers(){
			let _that = this;
			_that.om.request('tpromoteEvaluate/getResultList',{userId: _that.$refs.autoform.formdata.userId}).then(res=>{
				_that.resultList = res
				_that.$refs.autoform.changeEditor('resultInfo', 'resultCode', 'data', configSelectData(res, 'code', 'dicname'));
				_that.$refs.autoform.initSelectIndex('resultInfo', 'resultCode')
				_that.loadSalaryPos()
			})
			
		}
	},
	onLoad(options) {
		let _that = this;
		_that.menuName = options.title || '转正';
		uni.setNavigationBarTitle({
			title: _that.menuName
		});
		formShowLoading(_that)
		_that.busCode = options.code || "HRS0123";
		_that.initValue.zuserId = this.userId;
		_that.initValue.zuserName = this.userName;
		if(options.checkedit){
			if(typeof(options.checkedit) == 'string'){
				if(options.checkedit == "true"){
					_that.checkedit = true
				}
			}else{
				_that.checkedit = options.checkedit
			}
		}
		if(options.edit){
			if(typeof(options.edit) == 'string'){
				if(options.edit == "true"){
					_that.edit = true
				}
			}else{
				_that.edit = options.edit
			}
		}
		_that.initLoad(options);
	},
	onShow() {
		let _that = this
		if(_that.$refs.autoform){
			for(let fieldId in _that.subEditorObj){
				let editor = _that.subEditorObj[fieldId]
				uni.getStorage({
					key:getWorkCacheKey(fieldId),
					success:(res)=>{
						editor.workList = res.data
						if(fieldId =="title_salary"){ 
							let dataList = JSON.parse(JSON.stringify(_that.subEditorObj["title_salary"].workList))
								let num = ""
								for(let item of dataList){
									if(item.salaryName == "salary1"){
										num = Number(item.afterAdjust)
									}else if(item.salaryName =="salary2"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary3"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary4"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary5"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary6"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary7"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary8"){
										num = num - Number(item.afterAdjust)
									}else if(item.salaryName =="salary9"){
										item.afterAdjust = num
									}
								}
								_that.subEditorObj['title_salary'].workList = dataList
							}
							
							if(fieldId == "title_evaluate"){
								let score1 = 0
								let score2 = 0
								let score3 = 0
								for(let d of JSON.parse(JSON.stringify(res.data))){
									score1 += Number(d.standardScore)
									score2 += Number(d.parentEvaluateScore)
									score3 += Number(d.selfEvaluateScore)
								}
								let title1 = getEditorTitle("title_evaluate","standardScore",_that.subConfigData["title_evaluate"])
								let title2 = getEditorTitle("title_evaluate","parentEvaluateScore",_that.subConfigData["title_evaluate"])
								let title3 = getEditorTitle("title_evaluate","selfEvaluateScore",_that.subConfigData["title_evaluate"])
								if(_that.$refs.autoform.hasEditor("resultInfo","parentScore")){
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'parentScore',score2)
								}
								_that.calComprehensiveScore(score3,score2,_that.$refs.autoform.formdata.trainingEvaluationScore,_that.$refs.autoform.formdata.re_score).then(res=>{
									let comprehensiveScore = res.value
									if(_that.$refs.autoform.hasEditor("resultInfo","comprehensiveScore")){
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'comprehensiveScore',comprehensiveScore)
									}
								})
								if(_that.$refs.autoform.hasEditor("resultInfo","selfScore")){
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'selfScore',score3)
								}
								_that.$refs.autoform.changeEditor("title_evaluate","evaluateStr",{
									subBottomTitle:'合计:'+title1+'('+score1+')'+(title2?','+title2+'('+score2+')' :'')+(title3?','+title3+'('+score3+')' :'')
								})
							}
						uni.removeStorage({
							key:getWorkCacheKey(fieldId)
						})
					}
				})
			}
		}
	}
}
</script>
<style></style>
